package com.shine.chemicalWholeProcessSystem.ui.scoreQuery;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.impl.BottomListPopupView;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.lxj.xpopup.interfaces.OnSelectListener;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shine.chemicalWholeProcessSystem.BR;
import com.shine.chemicalWholeProcessSystem.R;
import com.shine.chemicalWholeProcessSystem.app.ChooseData;
import com.shine.chemicalWholeProcessSystem.app.Constants;
import com.shine.chemicalWholeProcessSystem.app.ScoreQueryBean;
import com.shine.chemicalWholeProcessSystem.base.BaseActivity;
import com.shine.chemicalWholeProcessSystem.bean.RiskManagementBean;
import com.shine.chemicalWholeProcessSystem.databinding.ActivityScoreQueryListBinding;
import com.shine.chemicalWholeProcessSystem.http.ApiException;
import com.shine.chemicalWholeProcessSystem.http.BaseReturn;
import com.shine.chemicalWholeProcessSystem.http.ECHttpResponse;
import com.shine.chemicalWholeProcessSystem.http.ECObserver;
import com.shine.chemicalWholeProcessSystem.http.ECObserverNew;
import com.shine.chemicalWholeProcessSystem.http.RetrofitClient;
import com.shine.chemicalWholeProcessSystem.http.RetrofitClientNew;
import com.shine.chemicalWholeProcessSystem.http.RxUtils;
import com.shine.chemicalWholeProcessSystem.http.Service;
import com.shine.chemicalWholeProcessSystem.ui.adapter.RiskManagementListAdapter;
import com.shine.chemicalWholeProcessSystem.ui.riskManagement.RiskManagementCreateActivity;
import com.shine.chemicalWholeProcessSystem.ui.riskManagement.RiskManagementDetailsActivity;
import com.shine.chemicalWholeProcessSystem.view.pop.RiskManagementSearchPopup;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.baseadapter.BGADivider;
import cn.bingoogolapple.baseadapter.BGAOnItemChildClickListener;
import cn.bingoogolapple.baseadapter.BGAOnRVItemClickListener;

public class ScoreQueryListActivity extends BaseActivity<ActivityScoreQueryListBinding, ScoreQueryViewModel> {
    private ArrayList<CoinInfo> mDataModels;
    private CoinAdapter adapter;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_score_query_list;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public ScoreQueryViewModel initViewModel() {
        return new ScoreQueryViewModel(this);
    }

    @Override
    public int appTheme() {
        return Constants.THEME_FULL;
    }

    @Override
    public void initData() {
        super.initData();
        setStatusBar();
        initTitle(this, "成绩查询");

        binding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                binding.refreshLayout.finishRefresh(1000);
                binding.refreshLayout.setEnableLoadMore(true);

//                dataList.clear();
//                riskManagementListAdapter.clear();

                getScoreQueryList();
            }
        });
        binding.refreshLayout.setEnableLoadMore(false);
//        binding.refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
//                binding.refreshLayout.finishLoadMore(1000);
//                page++;
//                getSensorHisAlarm();
//            }
//        });

        mDataModels = new ArrayList<>();
        for(int i=0;i<10000;i++) {
            CoinInfo coinInfo = new CoinInfo();
            coinInfo.name = "USDT";
            coinInfo.priceLast="20.0";
            coinInfo.riseRate24="0.2";
            coinInfo.vol24="10020";
            coinInfo.close="22.2";
            coinInfo.open="40.0";
            coinInfo.bid="33.2";
            coinInfo.ask="19.0";
            coinInfo.amountPercent = "33.3%";
            mDataModels.add(coinInfo);
        }

        binding.idHrecyclerview.setHeaderListData(getResources().getStringArray(R.array.right_title_name));

        getScoreQueryList();
    }

    private void getScoreQueryList() {
        showLoading("");
        RetrofitClientNew.getInstance().create(Service.class)
                .getScoreQuery("325688855656569874")
                .compose(RxUtils.<ECHttpResponse<ScoreQueryBean>>bindToLifecycle(this))
                .compose(RxUtils.<ECHttpResponse<ScoreQueryBean>>schedulersTransformer())
                .compose(RxUtils.<ECHttpResponse<ScoreQueryBean>>exceptionTransformer())
                .subscribe(new ECObserverNew<ScoreQueryBean>() {
                    @Override
                    protected void _onNext(ScoreQueryBean scoreQueryBean) {
                        dismissLoading();
                        adapter = new CoinAdapter(ScoreQueryListActivity.this, scoreQueryBean.getRows(), R.layout.item_layout);
                        binding.idHrecyclerview.setAdapter(adapter);

                    }

                    @Override
                    protected void _onError(ApiException ex) {
                        ToastMessage(ex.message);
                        dismissLoading();
                    }
                });
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {

                default:
                    break;
            }
        }
    }

}
